const express = require("express")

const router = express.Router();

const expressJoi = require("@escook/express-joi");

const { update_pwd_schema, update_nickname_schema, update_addressee_schema } = require("../schema/userinfo");

const userinfoHandler = require("../router_handler/userinfo");

const uuid = require("uuid");

const path = require("path");

const multer = require("multer");
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, "../assets"));
  },
  filename: function (req, file, cb) {
    let urlArr = file.originalname.split(".");
    cb(null, file.fieldname + "_" + uuid.v4() + '.' + urlArr[urlArr.length - 1]);
  }
});
const upload = multer({ storage: storage });


// 获取基本信息路由
router.get("/getInfo", userinfoHandler.getInfo);

// 获取收货信息路由
router.get("/getAddressee", userinfoHandler.getAddressee);

// 修改昵称路由
router.post("/updateNick", expressJoi(update_nickname_schema), userinfoHandler.updateNick);

// 修改密码路由
router.post("/updatePwd", expressJoi(update_pwd_schema), userinfoHandler.updatePwd);

// 修改头像路由
router.post("/updatePort", upload.single("user_portrait"), userinfoHandler.updatePort);

// 修改收货信息
router.post("/updateAddr", expressJoi(update_addressee_schema), userinfoHandler.updateAddressee);

module.exports = router;